#lang racket

;;;将列表中的原子提取出来合并到一个列表中
(define enumerate-tree
  (lambda (tree)
    (cond ((null? tree) '())
          ((not (pair? tree)) (list tree))
          (else (append (enumerate-tree (car tree))
                        (enumerate-tree (cdr tree)))))))
(enumerate-tree '(1 2 (3 4 (5 6) 7) (8 9)))

(define enumerate-tree1
  (lambda (tree)
    (cond ((null? tree) '())
          ((list? (car tree))
           (append (enumerate-tree1 (car tree))
                   (enumerate-tree1 (cdr tree))))
          (else (cons (car tree)
                      (enumerate-tree1 (cdr tree)))))))

(enumerate-tree1 '(1 2 (3 4 (5 6) 7) (8 9)))
